/* 
	@Copyright (c) 2007 by Denis Riabtchik. All rights reserved. See license.txt and http://jgrouse.com for details@
	$Id: TokenType.java 273 2007-12-09 00:46:43Z denis.riabtchik $
*/
package jgrouse.jgdoc;

public enum TokenType
{
	GEN_SINGLE_ATTR(false, 1),
	GEN_MULT_ATTR(false),
	FUNC_SINGLE_ATTR(false, 1),
	FUNC_MULT_ATTR(false),
	MEMBER_SINGLE_ATTR(false, 1),
	CLASS_MULT_ATTR(false),
	MODULE_MULT_ATTR(false),
	PROJECT_ATTR(false, 1),
	
	PHYS_CONTAINER(true, new TokenType[]{TokenType.GEN_SINGLE_ATTR, TokenType.GEN_MULT_ATTR, TokenType.MODULE_MULT_ATTR}),
	LOGICAL_CONTAINER(true, new TokenType[]{TokenType.GEN_SINGLE_ATTR, TokenType.GEN_MULT_ATTR, TokenType.CLASS_MULT_ATTR}),
	FUNCTION(true, new TokenType[]{TokenType.GEN_SINGLE_ATTR, TokenType.GEN_MULT_ATTR, 
				TokenType.FUNC_MULT_ATTR, TokenType.FUNC_SINGLE_ATTR, TokenType.MEMBER_SINGLE_ATTR}),
	VARIABLE(true, new TokenType[]{TokenType.GEN_SINGLE_ATTR, TokenType.GEN_MULT_ATTR, TokenType.MEMBER_SINGLE_ATTR}),
	CONTROL(true),
	CONTENT(false, 1),
	PROJECT(true, new TokenType[]{TokenType.GEN_SINGLE_ATTR, TokenType.GEN_MULT_ATTR, TokenType.PROJECT_ATTR});
	
	private boolean m_isTagType;
	private int m_arity;
	private TokenType[] m_allowedSubtags;
	
	TokenType(boolean pIsTagType)
	{
		m_isTagType = pIsTagType;
		m_arity = Integer.MAX_VALUE;
	}
	
	TokenType(boolean pIsTagType, TokenType[] pAllowed)
	{
		m_isTagType = pIsTagType;
		m_allowedSubtags = pAllowed;
		m_arity = 1;
	}
	
	TokenType(boolean pIsTagType, int pArity)
	{
		m_arity = pArity;
		m_isTagType = pIsTagType;
	}

	public int getArity()
	{
		return m_arity;
	}

	public boolean isTagType()
	{
		return m_isTagType;
	}
	
	public TokenType[] getAllowedSubtags()
	{
		return m_allowedSubtags;
	}
	
	public boolean isSubtagAllowed(TokenType pType)
	{
		if (m_allowedSubtags == null)
		{
			return false;
		}
		for (TokenType atype : m_allowedSubtags)
		{
			if (atype == pType)
			{
				return true;
			}
		}
		return false;
	}
}
